package com.example.easy.Service.Impl;

import com.example.easy.Dto.Visitor;
import com.example.easy.Service.myservice.VisitorServise;
import com.example.easy.mapper.VisitorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VisitorSerivelmpl implements VisitorServise {

    @Autowired
    VisitorMapper visitorMapper;

    @Override
    public boolean login(String username, String psd) {
        String sqlpsd = visitorMapper.selectPsd(username);
        if (sqlpsd == null) {
            return false;
        } else {
            if (psd.equals(visitorMapper.selectPsd(username))) {
                return true;
            } else {
                return false;
            }
        }
    }

    @Override
    public int regsiter(Visitor v) {
        if (visitorMapper.selectUid(v.getUsername()) == null) {
            visitorMapper.insVisitor(v);
            return 0;
        } else {
            return 401;
        }
    }

    @Override
    public Visitor selestuserinf(String username) {
        if (visitorMapper.selectUid(username) != null) {
            return visitorMapper.selectall(username);
        } else {
            return null;
        }
    }

    @Override
    public int update(Visitor visitor) {
        if (visitorMapper.selectUid(visitor.getUsername()) != null) {
            visitorMapper.update(visitor);
            return 1;
        } else return 0;
    }

    @Override
    public int delete(String username) {
        if (visitorMapper.selectUid(username) != null) {
            visitorMapper.delete(username);
            return 1;
        } else return 0;
    }


}
